package com.example.springbootblog.controller;


import com.example.springbootblog.common.pojo.request.AddBlogParam;
import com.example.springbootblog.common.pojo.request.BlogRequest;
import com.example.springbootblog.common.pojo.request.UpdateBlogParam;
import com.example.springbootblog.common.pojo.response.BlogInfoResponse;
import com.example.springbootblog.common.pojo.response.BlogResponse;
import com.example.springbootblog.service.BlogService;
import jakarta.annotation.Resource;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 博客控制层代码实现
 */

@Slf4j
@RequestMapping("/blog")
@RestController
public class BlogController {


    @Resource(name = "blogServiceImpl")
    BlogService blogService;



    @RequestMapping("/getList")
    public List<BlogInfoResponse> getList() {
        log.info("进入博客列表控制层...");
        List<BlogInfoResponse> list = blogService.getBlogs();
        System.out.println();
        return list;
    }

    @RequestMapping("/getListByPage")
    public BlogResponse<List<BlogInfoResponse>> getListByPage(BlogRequest pageRequest) {
        return blogService.getListByPage(pageRequest);
    }


    @RequestMapping("/getBlogDetail")
    public BlogInfoResponse getBlogDetail(@NonNull Integer blogId) {
        log.info("进行博客详情的控制层....");
        return blogService.getBlogDetail(blogId);
    }


    @RequestMapping("/addBlog")
    public boolean addBlog(@Validated @RequestBody AddBlogParam param) {
        return blogService.addBlog(param);
    }


    @RequestMapping("/update")
    public boolean update(@Validated @RequestBody UpdateBlogParam param) {
        return blogService.updateBlog(param);
    }

    @RequestMapping("/delete")
    public boolean delete(@NonNull Integer blogId) {
        return blogService.deleteBlogById(blogId);
    }
}
